<?php
namespace Modules\File\Forms;

use Modules\File\Forms\Element\FileBox;
use Modules\File\Forms\Element\File;
use Core\Forms\Form;

class FormElementInit
{
    public static function fileBox(Form &$t, $element)
    {
        $field = new FileBox($element['name'], $element['attributes']);
        return $field;
    }


    public static function file(Form &$t, &$element)
    {
        $field = new File($element['name'], $element['attributes']);
        $element += [
            'fileType' => [
                'jpeg' => 'jpeg',
                'png' => 'png',
                'jpg' => 'jpg',
                'gif' => 'gif',
            ],
            'num' => 1,
            'fileAccess' => 20,
            'minSize' => 10,
            'maxSize' => 900,
        ];
        if (empty($element['validate'])) {
            $element['validate'][] = array(
                'v' => 'File',
                'extension' => $element['fileType'],
                'maxSize' => $element['maxSize'],
                'minSize' => $element['minSize'],
                'message' => '只允许上传制定大小和类型的文件',
            );
        }
        return $field;
    }

    public static function fileBoxField(&$key, &$element)
    {
        $settings = $element['settings'];
    }
}